<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://zlzkj.com/tags" prefix="z" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE html>
<html>
<head>
    <title>鼎研能源管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
<div class="templatemo-content col-1 light-gray-bg">
    <div class="templatemo-content-container">
        <div class="templatemo-content-widget no-padding">
            <div class="zlzkj_item_content table-responsive">
                <div class="modal-header">
                    <div class="text-info"><p>角色管理</p></div>
                </div>
                <div class="col-sm-12">
                    <form id="search-form">
                        <input type="hidden" name="nowPage">
                        <div class="zlzkj_tool_bar">
                            <div class="zlzkj_left_tool_bar">
                                <input placeholder="角色名称" name="keyword">
                                <select name="isLocked" class="status_choose">
                                    <option value="">全部</option>
                                    <option value="0">启用</option>
                                    <option value="1">禁用</option>
                                </select>
                                <a class="searchUser btn btn-primary btm-sm"><i class="fa fa-search fa-fw"></i>搜索</a>
                            </div>
                            <div class="zlzkj_right_tool_bar">
                                <a class="create btn btn-primary btm-sm"><i class="fa fa-plus fa-fw"></i>添加</a>
                                <a class="batchDeleteUser btn btn-danger btm-sm"><i
                                        class="fa fa-trash-o fa-fw"></i>删除</a>
                            </div>
                        </div>
                    </form>
                    <div id="user-view">
                        <form class="ids-form">
                            <table class="zlzkj_table table table-striped table-hover"><%--table-bordered--%>
                                <thead>
                                <tr>
                                    <th width="15%"><a href="javascript:void(0)" class="checkall">全选</a></th>
                                    <th width="15%">角色名称</th>
                                    <th width="45%">简介</th>
                                    <th width="10%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <%--<c:forEach var="v" items="${pageView.page.items}">
                                    <tr data-id="${v.id}" data-name="${v.name}">
                                        <td><input type="checkbox" name="id" value="${v.id}"></td>
                                        <td>${v.name}</td>
                                        <td>${v.role_name}</td>
                                        <td>
                                            <input type="button" class="btn btn-default btn-sm edit" value="编辑">
                                            <input type="button" class="btn btn-default btn-sm deleteUser" value="删除">
                                        </td>
                                    </tr>
                                </c:forEach>
                                <c:if test="${pageView.page.items.size() == 0}">
                                    <tr>
                                        <td colspan="8" align="center">暂无数据</td>
                                    </tr>
                                </c:if>--%>
                                </tbody>
                            </table>
                         </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div id="reportview"></div>
        <footer class="zlzkj_footer">
            <p>Copyright &copy; HangZhou DingYan Tech
                | 杭州鼎研科技有限公司版权所有</p>
        </footer>
    </div>
</div>

<%--增删改查的工具类--%>
<script type="text/javascript" src="${__static__}/js/operation/operation.js"></script>

<script type="text/javascript">
    $(function () {

        $(".search").off("click").on("click", function () {
            refreshTable(1);
        });

        $(".table-view").zlzjkLoading();
        refreshTable(1);

    });

    //刷新数据
    function refreshTable(nowPage) {
        $(".table-view").zRefresh('${z:u('role/list')}',nowPage);
    }

    //给按钮绑定基本事件
    function initOperation(){
        $(".create").onZCreate('${z:u('role/toCreate')}',formValidate);
        $(".edit").onZEdit('${z:u('role/toEdit')}',formValidate);
        $(".delete").onZDelete('${z:u('role/delete')}');
        $(".enable").onZEnable('${z:u('role/enable')}');
        $(".disable").onZDisable('${z:u('role/disable')}');
    }

    //用户表单验证
    function formValidate() {
        $("#commonModal").modal('show');
        $('#user-form').validate(
            {
                submitHandler: function (form) {
                    $(".confirm").button('loading');
                    $(form).ajaxSubmit({
                        dataType: "json",
                        type: "post",
                        success: function (data, s, xhr) {
                            if (data == 1) {
                                refreshTable(0);
                                $(".confirm").button('reset');
                                $("#commonModal").modal('hide');
                            }
                        }
                    });
                },
                errorPlacement: function (error, element) {
                    error.replaceAll($(element).next());
                },
                rules: {

                    name: {
                        maxlength: 30,
                        required: true,
                        remote: {
                            url: '${z:u('role/checkName')}',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                name: function () {
                                    return $("[name='name']").val();
                                },
                                originalname: ""
                            }
                        }
                    },
                    roleId: {
                        required: true
                    },

                    description: {
                        maxlength: 100
                    }
                },
                messages: {

                    name: {
                        required: "必填！",
                        remote: "已存在！"
                    },

                    roleId: {
                        required: "请选择！"
                    }
                },
                success: function (label) {
                    label.hide();
                }
            });

        /*$('[name=startTime]').datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'zh',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 3,
            forceParse: 0
        });*/
    }

</script>
<!--添加和修改页-->
<script type="text/html" id="objTemplate">
    <form id="user-form" method="post" class="form-horizontal" role="form" action="{%= obj.id == null ? '${z:u('user/create')}':'${z:u('user/update')}'%}" autocomplete="off" >
        <input name="id" type="hidden" value="{%= obj.id %}">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            {%if obj.id == null %}
            <h4 class="head">添加角色</h4>
            {%else%}
            <h4 class="head">修改角色信息</h4>
            {%/if%}
        </div>
        <div class="modal-body">
            <div class="form-group col-sm-12 ">
                <label class="col-sm-2 control-label">角色名称：</label>
                <div class="col-sm-4">
                    <input name="name" class="form-control" value="{%= obj.name %}">
                    <label class="control-label"></label>
                </div>
                <label class="col-sm-2 control-label">简介：</label>
                <div class="col-sm-4">
                    <textarea name="description" class="form-control" >{%= obj.description %}</textarea>
                    <label class="control-label"></label>
                </div>
            </div>
            <div class="form-group col-sm-12 ">
                <label class="col-sm-2 control-label">角色权限：</label>
                <div class="col-sm-10">
                    <div class="box">
                        <div class="box-header with-border">
                            能源监控
                        </div>
                        <div class="authority-group">
                            <input name="authorityIds" value="1" type="checkbox" {%= contain(authorities,'equipment_map') %} ><span>实时监控</span>
                            <input name="authorityIds" value="2" type="checkbox" {%= contain(authorities,'equipment_manage') %}><span>能源监控消耗</span>
                        </div>
                    </div>
                    <div class="box">
                        <div class="box-header with-border">
                            设备管理
                        </div>
                        <div class="authority-group">
                            <input name="authorityIds" value="1" type="checkbox" {%= contain(authorities,'equipment_map') %} ><span>设备查询</span>
                            <input name="authorityIds" value="2" type="checkbox" {%= contain(authorities,'equipment_manage') %}><span>设备入库</span>
                            <input name="authorityIds" value="3" type="checkbox" {%= contain(authorities,'equipment_category') %}><span>设备安装</span>
                            <input name="authorityIds" value="4" type="checkbox" {%= contain(authorities,'equipment_region') %}><span>设备检修</span>
                        </div>
                    </div>
                    <div class="box">
                        <div class="box-header with-border">
                            警报管理
                        </div>
                        <div class="authority-group">
                            <input name="authorityIds" value="6" type="checkbox" {%= contain(authorities,'warning_index') %}><span>报警清单</span>
                            <%--<input name="authorityIds" value="7" type="checkbox" {%= contain(authorities,'warning_location') %}><span>实时定位</span>--%>
                            <input name="authorityIds" value="8" type="checkbox" {%= contain(authorities,'warning_threshold') %}><span>阈值设定</span>
                        </div>
                    </div>
                    <div class="box">
                        <div class="box-header with-border">
                            控制决策
                        </div>
                        <div class="authority-group">
                            <input name="authorityIds" value="9" type="checkbox" {%= contain(authorities,'enterprise_index') %}><span>决策方案</span>
                            <input name="authorityIds" value="10" type="checkbox" {%= contain(authorities,'role_index') %}><span>管理</span>
                            <input name="authorityIds" value="11" type="checkbox" {%= contain(authorities,'user_index') %}><span>test</span>
                        </div>
                    </div>

                    <shiro:hasAnyRoles name="SUPER_ADMIN">
                        <div class="box">
                            <div class="box-header with-border">
                                系统管理
                            </div>
                            <div class="authority-group">
                                <input name="authorityIds" value="12" type="checkbox" {%= contain(authorities,'backup_index') %}><span>角色管理</span>
                                <input name="authorityIds" value="13" type="checkbox" {%= contain(authorities,'tenant_index') %}><span>日志操作</span>
                                <input name="authorityIds" value="13" type="checkbox" {%= contain(authorities,'tenant_index') %}><span>人员管理</span>

                            </div>
                        </div>
                    </shiro:hasAnyRoles>
                </div>
            </div>
        </div>
        <div style="clear: both;"></div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary confirm btn-sm" data-loading-text="加载中.." value="提交"/>
            <a class="btn btn-primary common-modal-cancel btn-sm">取消</a>
        </div>
    </form>
</script>

<script type="text/html" id="tableTemplate">
    <form class="ids-form">

        <table class="zlzkj_table table table-striped table-hover" style="margin-top: 5px"><%--table-bordered--%>
            <thead>
            <tr>
                <th width="3%">
                    <a href="javascript:void(0)" class="checkall">全选</a>
                </th>
                <th width="10%">角色名称</th>
                <th width="10%">简介</th>
                <%--<th width="5%">状态</th>
                <th width="10%">创建时间</th>--%>
                <th width="10%">操作</th>
            </tr>
            </thead>
            <tbody>
            {%each(i,v) pageView.page.items %}
            <tr data-id="{%= v.id %}" data-name="{%= v.name%}">
                <td>
                    <input type="checkbox" name="id" value="{%= v.id %}">
                </td>
                <td>{%= v.name %}</td>
                <td>{%= v.description%}</td>
               <%-- <td>
                    {%if v.is_locked == 0%}
                    <span class="tag-success">启用</span>
                    {%elseif v.is_locked == 1%}
                    <span class="tag-danger">禁用</span>
                    {%/if%}
                </td>
                <td>{%= formatTime(v.created_time,'yyyy-MM-dd HH:mm:ss') %}</td>--%>
                <td>

                   <%-- {%if v.is_system != 1%}
                    <input type="button" class="btn btn-default btn-sm edit" value="编辑">
                    {%if v.is_locked == 0%}
                    <input type="button" class="btn btn-default btn-sm disable"
                           value="禁用">
                    {%elseif v.is_locked == 1%}
                    <input type="button" class="btn btn-default btn-sm enable"
                           value="启用">
                    {%/if%}
                    <input type="button" class="btn btn-default btn-sm delete" value="删除">
                    {%/if%}--%>
                    <input type="button" class="btn btn-default btn-sm edit" value="编辑">
                    <input type="button" class="btn btn-default btn-sm delete" value="删除">

                </td>
            </tr>
            {%/each%}
            {%if pageView.page.items.length == 0%}
            <tr>
                <td colspan="8" align="center">暂无数据</td>
            </tr>
            {%/if%}
            </tbody>
        </table>
    </form>
</script>
</body>
</html>